from django.db import models

# Create your models here.
from django.utils.html import format_html




class Total(models.Model):

    jobName = models.CharField(max_length=65, verbose_name="岗位名称", null=True, blank=True)
    brandName = models.CharField(max_length=65, verbose_name="公司名称",null=True,blank=True)
    brandLogo = models.CharField(max_length=65, verbose_name="公司LOGO",null=True,blank=True)
    url = models.CharField(max_length=65, verbose_name="详情",null=True,blank=True)
    wages = models.FloatField(verbose_name="工资",null=True,blank=True)
    bossName = models.CharField(max_length=65, verbose_name="招聘人",null=True,blank=True)
    bossTitle = models.CharField(max_length=65, verbose_name="招聘人职位",null=True,blank=True)
    jobExperience = models.CharField(max_length=65, verbose_name="需求经验",null=True,blank=True)
    jobDegree = models.CharField(max_length=65, verbose_name="学历",null=True,blank=True)
    skills = models.CharField(max_length=65, verbose_name="掌握技能",null=True,blank=True)
    cityName = models.CharField(max_length=65, verbose_name="城市",null=True,blank=True)
    province = models.CharField(max_length=65, verbose_name="省份",null=True,blank=True)
    areaDistrict = models.CharField(max_length=65, verbose_name="区域",null=True,blank=True)
    brandStageName = models.CharField(max_length=65, verbose_name="融资情况",null=True,blank=True)
    brandIndustry = models.CharField(max_length=65, verbose_name="公司类别",null=True,blank=True)
    brandScaleName = models.CharField(max_length=65, verbose_name="公司规模",null=True,blank=True)
    welfareList = models.CharField(max_length=65, verbose_name="福利",null=True,blank=True)

    def __str__(self):
        return self.jobName

    def href_link(self):
        path = self.url
        button_html = "<a  href='{}'  target='_blank'>跳转详情</a>".format(path)
        return format_html(button_html)

    def collection(self):
        button_html = "<a  href='/api/collection?name={}&url={}'  >点击收藏</a>".format(self.jobName,self.url)
        return format_html(button_html)

    collection.short_description = format_html("""<a  href='#' style="position: relative;left: -12px;">收藏</a>""")

    href_link.short_description = format_html("""<a  href='#' style="position: relative;left: -12px; target='_blank'  ">跳转查看</a>""")

    class Meta:
        verbose_name = "Boss直聘"
        verbose_name_plural = verbose_name
        db_table = 'Total'



class CityMsg(models.Model):

    name = models.CharField(max_length=255, verbose_name="名称", null=True, blank=True)
    code = models.CharField(max_length=255, verbose_name="代码", null=True, blank=True)

    def __str__(self):
        return self.name

    class Meta:
        verbose_name = "地区代码"
        verbose_name_plural = verbose_name
        db_table = 'CityMsg'





class Cookies(models.Model):

    cookies = models.TextField(max_length=65500, verbose_name="cookies", null=True, blank=True)

    def __str__(self):
        return self.cookies

    class Meta:
        verbose_name = "爬虫配置"
        verbose_name_plural = verbose_name
        db_table = 'u_cookies'






class Colect(models.Model):

    co_title = models.CharField(verbose_name="收藏",max_length=255)
    co_down_link = models.CharField(verbose_name="收藏地址",max_length=255)

    def __str__(self):
        return self.co_title

    def href_link(self):
        path = self.co_down_link
        button_html = "<a  href='{}'  >跳转详情</a>".format(path)
        return format_html(button_html)
    href_link.short_description = format_html("""<a  href='#' style="position: relative;left: -12px; target='_blank'  ">跳转查看</a>""")

    class Meta:
        verbose_name = "收藏列表"
        verbose_name_plural = verbose_name
        db_table = 'Colect'




